local hx__shinan = fk.CreateSkill {
  name = "hx__shinan",
  tags = { Skill.Compulsory, },
}

hx__shinan:addEffect(fk.Damaged, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(hx__shinan.name) then
      if target:getMark("hx__shinan-turn") == 0 then
        event:setCostData(self, {choice = "recover"})
        return target:isWounded()
      elseif target:getMark("hx__shinan-turn") ~= 0 then
        event:setCostData(self, {choice = "loseHp"})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(hx__shinan.name)
    local choice = event:getCostData(self).choice
    if choice == "recover" then
      room:notifySkillInvoked(player, hx__shinan.name, "defensive")
      room:recover{
        who = target,
        num = 1,
        recoverBy = player,
        skillName = hx__shinan.name,
      }
      room:addPlayerMark(target, "hx__shinan-turn")
    else
      room:notifySkillInvoked(player, hx__shinan.name, "negative")
      room:loseHp(target, 1, hx__shinan.name)
    end
  end,
})

return hx__shinan